package com.glela.controller;


import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.*;
import com.glela.platform.model.request.*;
import com.glela.platform.model.response.*;
import com.glela.platform.service.*;
import com.glela.platform.util.ParameterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/promotiongift")
public class UserPromotionGiftController {
	private static Logger logger = LoggerFactory.getLogger(UserPromotionGiftController.class);

    @Autowired
    private UserPromotionGiftService userPromotionGiftService;

	/**
	 * 查询（讲师）赠送礼包给指定邀请人（学生）的领取记录
	 * @param requestUserModel
	 * @return
	 * @author zhangrenjie
	 * @date 2017年11月14日 下午4:24:02
	 */
	@ResponseBody
	@RequestMapping(value = "/selectGetPromotionRecord", method = RequestMethod.POST, consumes = "application/json")
	public ResponseEntity<?> selectGetPromotionRecord(@RequestBody RequestUserPromotionModel requestUserModel) {
		try {
			if (ParameterUtils.validParams(requestUserModel.getLoginUserId(),requestUserModel.getInviterUserId())) {
				return new ResponseEntity<ResponseBaseModel>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
			}
            MyattentionTalent promotionList = userPromotionGiftService.selectGetPromotionRecordPage(
                    requestUserModel.getLoginUserId(),requestUserModel.getInviterUserId(), requestUserModel.getStartIndex(),
					requestUserModel.getPageSize());
            return new ResponseEntity<>(new ResponseResultModel<MyattentionTalent>(promotionList),
					HttpStatus.OK);
		} catch (Exception e) {
			logger.error("查询赠送礼包领取记录异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}
    /**
     * 初始化赠送礼包列表（弹窗弹出礼包列表）
     * @param requestMap
     * @return
     * @author zhangrenjie
     * @date 2017年11月15日 下午2:24:02
     */
    @ResponseBody
    @RequestMapping(value = "/getGiftPromotionList", method = RequestMethod.POST, consumes = "application/json")
    public ResponseEntity<?> getGiftPromotionList(@RequestBody RequestUserPromotionModel requestUserModel) {
        try {
//            if (null == requestMap || requestMap.isEmpty()) {
//                return new ResponseEntity<ResponseBaseModel>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
//            }
//			if (ParameterUtils.validParams(requestMap.get("loginUserId"))) {
//				return new ResponseEntity<ResponseBaseModel>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
//			}
			if (ParameterUtils.validParams(requestUserModel.getLoginUserId(),requestUserModel.getInviterUserId())) {
				return new ResponseEntity<ResponseBaseModel>(new ResponseBaseModel(ErrorEnum.C20102), HttpStatus.OK);
			}
			List<ResponsePromotionVo> promotionVoList =  userPromotionGiftService.selectGiftPromotionListByteacherId(
					requestUserModel.getLoginUserId().toString(),requestUserModel.getInviterUserId().toString());
            return new ResponseEntity<>(new ResponseResultModel<List<ResponsePromotionVo>>(promotionVoList),
                    HttpStatus.OK);
        } catch (Exception e) {
            logger.error("查询讲师可赠送礼包列表异常:", e);
            return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
        }
    }
	
}
